\chapter{Technical documentation}

\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white, singlelinecheck=false, margin=0pt, font={bf,footnotesize}}

\section{Mario AI Benchmark technical documentation} 
This section contains the summary of all level components, short description and how to use them.
\begin{itemize}
	\item \emph{Level Height} is in range [15..20] in versions up to $0.1.8$. It is going to be arbitrary in versions $0.2$ and higher.
	Example:
	\texttt{java ch.idsia.scenarios.Main -lh 18} will set the height to 18.
	Default: 15.
	\item Dead ends (-lde <on|off>)
	This option allows to have a control over dead ends on a level.
	Example:
	\texttt{java ch.idsia.scenarios.Main -lde on} will show the level with dead ends.
	Default: off
	\item Cannons (-lc <on|off>)
	If you want to disable cannons on the level, then you should use this option.
	Available states: on, off.
	By default cannons are enabled.
	For example:
	java ch.idsia.scenarios.Main -lc off will show the level without cannons.
	\item Enable/disable hills (-lhs on/off)
	If you want to disable hills on the level, then you should use this option.
	Available states: on, off.
	By default cannons are enabled.
	For example:
	java ch.idsia.scenarios.Main -lhs off will create level without hills.
	\item Enable/disable tubes (-ltb on/off)
	If you want to disable tubes on the level, then you should use this option.
	Available states: on, off.
	By default tubes are enabled.
	For example:
	java ch.idsia.scenarios.Main -ltb off will create level without tubes.
	\item Enable/disable gaps (-lg on/off)
	If you want to disable gaps on the level, then you should use this option.
	Available states: on, off.
	By default gaps are enabled.
	For example:
	java ch.idsia.scenarios.Main -lg off will create level without gaps.
	\item Enable/disable hidden blocks (-lhb on/off)
	If you want to disable hidden blocks on the level, then you should use this option. If level is build with dead ends and without hidden blocks, thn you will gou out from dead end over visible blocks, e.g. hidden blocks are replaced with visible blocks.
	Available states: on, off.
	By default hidden blocks are Disabled.
	For example:
	java ch.idsia.scenarios.Main -lhb off will create level without hidden blocks.
	\item Enable/disable enemies (-le on/off)
	If you want to disable enemies on the level, then you should use this option.
	Available states: on, off.
	By default enemies are enabled.
	For example:
	java ch.idsia.scenarios.Main -le off will create level without enemies.
	
	\item Enable/disable blocks (-lb on/off)
	If you want to disable blocks on the level, then you should use this option.
	Available states: on, off.
	By default blocks are enabled.
	For example:
	java ch.idsia.scenarios.Main -ld off will create level without blocks.
	\item Enable/disable coins (-lco on/off)
	If you want to disable coins on the level, then you should use this option.
	Available states: on, off.
	By default coins are enabled.
	For example:
	java ch.idsia.scenarios.Main -lco off will create level without coins.
	
	\item More usage examples:
	\begin{enumerate}
		\item To get a flat level you need to disable all elements of the level: 
		java ch.idsia.scenarios.Main -lco off -lb off -le off -lhb off -lg off -ltb off -lhs off -lc off -lde off
		\item To get a level without dead ends and enemies and other options enabled:
		java ch.idsia.scenarios.Main -lde off -le off
		\item To get a level with dead ends and without hidden blocks and other options enabled:
		java ch.idsia.scenarios.Main -lhb off
		\item To get a flat level with dead ends and just only visible blocks:
		java ch.idsia.scenarios.Main -lco off -le off -lhb off -lg off -ltb off -lhs off -lc off		
	\end{enumerate}
\end{itemize}

\section{Ami\textbf{C}o technical documentation} 
\section{User's guide}
\texttt{AmiCoPyJava} is a library, that makes possible to call \texttt{Java} methods from your \texttt{Python} script without a line of code you have to write in \texttt{C/C++} or any other language. The \texttt{Python} source-code is so-called "active code", and the \texttt{Java} code is passive one. This part of the document describes how does \texttt{AmiCoPyJava} work and how to use it.

This native bridge is possible due to native \texttt{C++} bindings for both \texttt{Java} and \texttt{Python}. Library allows to invoke both static and non-static methods of a target \texttt{Java} class and provides complete access to \texttt{JNI}\footnote{\texttt{Java} Native Interface} methods from \texttt{Python}. 

\subsection{AmiCoPyJava Methods}
There are two kinds of methods: 
\begin{enumerate}
	\item methods returns a value of primitive type
	\item methods returns an array of primitive types
\end{enumerate}

Values of primitive types are passed between \texttt{Java} and \texttt{AmiCo}, \texttt{AmiCo} and \texttt{Python}: \emph{numeric} and \emph{floating point} types, \emph{strings} and \emph{arrays} of primitive types. Full  specification of supported types is presented in Table~\ref{table:PythonJavaTypes}.
\begin{table}[h]
\center{
\begin{tabular}{ | c | c | c |  c | }
	\hline
	Python			& ctypes	& C++                 		& Java \\ \hline \hline
	1-character string 	& c\_ushort	& unsigned short 		&char \\ \hline
	int/long		& c\_ubyte	& unsigned char  		& boolean \\ \hline
	int/long		& c\_byte	& signed char	     		& byte \\ \hline
	int/long		& c\_short	& short	 	  		& short \\ \hline
	int/long		& c\_int	& int		     		& int \\ \hline
	int/long		& c\_longlong	& long long     		& long \\ \hline
	float			& c\_float	& float		     		& float \\ \hline
	float			& c\_double	& double	     		& double \\ \hline
	String or None		& c\_char\_p	& char* (NUL terminated)	& String \\ \hline
	Tuple			& py\_object	& $<$type$>$**			& native array of $<$type$>$ \\
 	\hline
\end{tabular}
}\caption{Matching of types for \texttt{Python},\texttt{ C++}, \texttt{Java}  } \label{table:PythonJavaTypes}
\end{table}

\subsection{Initialization}
\texttt{void amicoInitialize(int nOptions = 0, ...)} creates \texttt{JVM} with given startup options (like parameters of the function). It takes number of arguments as first parameter which is optionally followed by string arguments matching this number. They are the JVM startup options. For example:

\lstinline{libamico.amicoInitialize(1, "-Xmn256M")}

\texttt{void loadJavaClass(const char* javaClassName)} loads and instantiates the \texttt{Java} class. This class contains methods user would like to be called. For example:

\lstinline{libamico.loadJavaClass("ch.idsia.helloUniverce")}

It takes one parameter -- fully qualified name of the class to be loaded.

If there are any errors or exceptions during initialization process, detailed error messages are emitted to standard error output. That's it! Setup is finished and methods from your Java class are available for invokation.

Finally, close AmiCo and destroy the \texttt{JVM} environment with \texttt{amicoClose()} function.

\subsection {Accessing \texttt{Java} class methods}

\subsubsection{Dealing with primitive types} % (fold)
\label{ssub:dealing_with_primitive_types}

% subsubsection dealing_with_primitive_types (end)
To access any method of the Java class you first have to store methods' IDs using \texttt{void* getMethod(const char* mName, const char* mSign)} function for each method you're going to use. It takes a name of the method and it's signature as parameters and returns ID of the method which can be stored in \texttt{Python} variable if method matching name and signature found in \texttt{Java} class or \texttt{NULL} otherwise. After that you can call that method using one of the functions from the \texttt{call<Type>Method} group where \texttt{<Type>} is a type of return value (e.g. \texttt{callIntMethod})

There are functions of three kinds: 
\begin{itemize}
	\item functions returning a value of any primitive type
	\item functions returning an array of primitive type values
	\item void functions
\end{itemize}
To call required method you should select appropriate method regarding the type of the return value of the \texttt{Java} method. For instance, suppose a method \texttt{int sumOfThree(int a, int b, int c)} (listing~\ref{listing:callSumOfThree}) in your \texttt{Java} class is a method of interest:

\begin{lstlisting}[caption=Calling sumOfThree method, label=listing:callSumOfThree]
#will give you an ID of the method
sumOfThree = libamico.getMethod("sumOfThree", "(III)I")   
#will call a \texttt{sum} method and return you a result as int
res = libamico.callIntMethod(sumOfThree, 1, 2, 3) 
\end{lstlisting}

Sometimes \texttt{Python} doesn't know how to interpret a certain type so you should manually declare type(s) of the function options using an \texttt{argtype} property of the function in \texttt{Python} script (listing~\ref{listing:argtypeProperty}). First parameter in every function will always be a \texttt{ctypes.c\_void\_p} and another could have any type from \texttt{ctypes}:

\begin{lstlisting}[caption=Using argtype property, label=listing:argtypeProperty]
sumOfThree = libamico.getMethod("sumOfThree", "(III)I")
# args types
libamico.callIntMethod.argtypes = [ctypes.c_void_p, c_int, c_int, c_int]
# result type
libamico.callIntMethod.restype = c_int
res = libamico.callIntMethod(sumOfThree, 1, 2, 3)
\end{lstlisting}

It is of course also possible to pass arguments with different types (listing~\ref{listing:differentTypes}):
\begin{lstlisting}[caption=Passing arguments with different types, label=listing:differentTypes]
threeTypes = libamico.getMethod("intStringLong", "(ILjava/lang/String;J)V")
libamico.callVoidMethod.argtypes = [ctypes.c_void_p, c_int, c_char_p, c_long]
libamico.callVoidMethod(threeTypes, 1, "int, String and long", 2)
\end{lstlisting}

\subsubsection{Dealing with arrays} % (fold)
\label{ssub:dealing_with_arrays}

% subsubsection dealing_with_arrays (end)
% subsection dealing_with_arrays (end)
This section describes how to pass arrays as arguments and how to receive arrays as a return value from a method. Passing an array requires three steps to complete: 
\begin{itemize}
	\item set size of array(s) 
	\item set arguments types for the function
	\item convert array to the tuple
\end{itemize}

To set size of arrays use function \texttt{void setSizeOfArrays(unsigned int size, unsigned int* s)} (listing~\ref{listing:settingSizeOfArrays}). It takes $2$ arguments: number of arrays to be passed and tuple, containing sizes for those arrays by ID.

\begin{lstlisting}[caption=Setting size of array(s), label=listing:settingSizeOfArrays]
ar1 = (1, 2, 3) # first array represented as tuple
ar2 = (4, 5, 6) # second array represented as tuple
# take ID of the method
arrays = libamico.getMethod("sumOfTwoIntArrays", "([I[I)V")
# set arguments types for setSizeOfArrays function
# first is an integer and second is an array
libamico.setSizeOfArrays.argtypes = [c_int, ListPOINTER(c_int)]
# call function to set size of arrays
libamico.setSizeOfArrays(2, (3, len(ar2)))
# set arguments types for the function to call a method
libamico.callVoidMethod.argtypes = [ctypes.c_void_p, ListPOINTER(c_int), ListPOINTER(c_int)]
# call a method with an arrays as arguments
libamico.callVoidMethod(arrays, ar1, ar2)
\end{lstlisting}

Here we are using a strange object \texttt{ListPOINTER(object)} (listing~\ref{listing:ListPOINTER}) to tell \texttt{Python} that concrete argument is an array. The code of this class comes next:

\begin{lstlisting}[caption=ListPOINTER, label=listing:ListPOINTER]
class ListPOINTER(object):
    def __init__(self, etype):
        self.etype = etype

    def from_param(self, param):
        if isinstance(param, (list, tuple)):
            return (self.etype * len(param))(*param)
        else:
            return param
\end{lstlisting}

Copy-n-paste this class into your source code to use it. Lets forward question on how this weird piece of code does work to Siberian shamans or don Juan, it's too esoteric to explain it here.

To call a method that returns a tuple as result, use one of the functions from \texttt{PyObject* call<Type>ArrayMethod(void* midUInt, ...)} group regarding the type of the elements to be returned. Here you need to set up result type of the function to \texttt{py\_object} (listing~\ref{listing:stringsArrayAsResult}):

\begin{lstlisting}[caption=Method returning an array of strings as result, label=listing:stringsArrayAsResult]
# take an ID of the method that will return an array of strings
array = libamico.getMethod("getStringArray", "()[Ljava/lang/String;")
# set types of arguments
libamico.callStringArrayMethod.argtypes = [ctypes.c_void_p]
# set result type
libamico.callStringArrayMethod.restype = py_object
# call method
strings = libamico.callStringArrayMethod(array)
# strings is a Python tuple with strings returned by getStringArray() method
\end{lstlisting}

\subsection{Specification of \texttt{AmiCoPyJava} Functions}
This section contains the complete specification of the \texttt{AmiCoPyJava} functions. For each function, we provide information about the following:
\begin{itemize}
\item function prototypes
\item a detailed description, including the parameters and return values
\end{itemize}

See section~\ref{struct:ReferenceGuide} for information about all functions of the library, and section~\ref{_python_calls_java_8h} for information abou functions exported by the library.


\subsection{Compiling \texttt{AmiCoPyJava} library}
\label{subs:compile}
To compile a library you need to have \texttt{Java} and \texttt{Python SDK} include files installed as like as standard Developer Tools (more details are in platform specific subsections ~\autoref{linux, osx}). There are two ways to compile a library: using makefile or manual compiling. To compile using makefile just \texttt{cd} to the directory where you has downloaded sources and run \texttt{make}:

\begin{lstlisting}[language=bash, frame=none, keywordstyle=\color{black}, numbers=none]
$ cd AmiCo/AmiCoPyJava
$ make
\end{lstlisting}
After this step you'll have a new directory named \texttt{build}. Inside this directory it will be one file of the dynamic library -- \texttt{libAmiCoPyJava.dylib} if you are using \texttt{MacOS} or \texttt{libAmiCoPyJava.so} if you are using \texttt{Linux}. That's it, AmiCo library is ready for using! This way is equal for both MacOS and Linux and it will work perfect only if you have a standard system paths. 

\subsubsection{Linux} \label{linux}
If you have to compile the library manually or experiencing any troubles with standard Makefile, you should locate your \texttt{Java} and \texttt{Python} include files. Assume \texttt{Java} include files are located in \texttt{/usr/lib/jvm/java/include} and \texttt{/usr/lib/jvm/java/include/linux} directories and \texttt{Python} include files are located in \texttt{/usr/include/python2.6}. There are also several standard libraries that we will need to compile: \texttt{pthread, z, util}. You also need paths to \texttt{JVM} libraries too: \texttt{/usr/lib/jvm/java/jre/lib} and \texttt{/usr/lib/jvm/java/jre/lib/i386/server} (possibly, these paths will be different on your machine if you have non-standard system installation paths).

By this step all should have set up and you have all you need and ready to compile. Note, that all commands go into a single line):

\begin{lstlisting}[language=bash, frame=none, numbers=none, keywordstyle=\color{black}]
$ cd AmiCo/AmiCoPyJava
$ mkdir build
$ g++ -shared -Wl,-soname,libAmiCoPyJava.so.1 -fPIC -I/usr/include/python2.6 -I/usr/lib/jvm/java/include -I/usr/lib/jvm/java/include/linux -L/usr/lib/jvm/java/jre/lib -L/usr/lib/jvm/java/jre/lib/i386/server -ljvm -lpthread -lz -lutil -o build/libAmiCoPyJava.so src/PythonCallsJava.cc
\end{lstlisting}

After that you can find \texttt{libAmiCoPyJava.so} in \texttt{build} directory. Make sure either to put it onto standard path or export current path to LD\_LIBRARY\_PATH.

\subsubsection{Mac OS X}
This section describes OS X specific compile and link options.

\subsection{Running a simple program, "Hello Universe!"}

Now let's write our first example program that will demonstrate capabilities of the library. Our first greeting is \texttt{HelloUniverse}\footnote{It turned that demo is too large to call it "Hello, World"}.

First of all we need a \texttt{Java} class and some methods we are going to calle from \texttt{Python}. Lets demonstrate most useful use cases:

\begin{enumerate}
\item \texttt{void printHelloUniverse()} -- prints a simple string
\begin{lstlisting}[language=java, frame=none, numbers=none]
public void printHelloUniverse()
{
    System.out.println("Hello Universe!");
}
\end{lstlisting}
\item \texttt{void printCustomString(String str)} - prints a string passed from \texttt{Python} as parameter
\begin{lstlisting}[language=java, frame=none, numbers=none]
public void printCustomString(String str)
{
    System.out.println(str);
}
\end{lstlisting}
\item \texttt{void passArrayOfIntegers(int[] array)} - prints each element of the passed from \texttt{Python} array
\begin{lstlisting}[language=java, frame=none, numbers=none]
public void passArrayOfIntegers(int[] array)
{
    for (int i = 0; i < array.length; i++)
        System.out.println ("array[" + i + "] = " + array[i]);
}
\end{lstlisting}
\item \texttt{float[] getArrayOfFloats()} --- returns an array of floats back to Python
\begin{lstlisting}[language=java, frame=none, numbers=none]
public float[] getArrayOfFloats()
{
    float[] res = {2.43f, 835.34536f, 2456.234f, -234.213f};
    return res;
}
\end{lstlisting}
\item \texttt{String getIntAsString(int i)} --- takes integer as parameter, converts it to the string and returns string back to Python
\begin{lstlisting}[language=java, frame=none, numbers=none]
public String getIntAsString(int i)
{
    String s = String.valueOf(i);
    return s;
}
\end{lstlisting}
\item \texttt{float sumOfFloatAndInt\_AsFloat(float fl, int i)} --- takes float and integer arguments, adds them and returns sum as float
\begin{lstlisting}[language=java, frame=none, numbers=none]
public float sumOfFloatAndInt_AsFloat(float fl, int i)
{
    System.out.println("float: " + fl);
    System.out.println("integer: " + i);
    return (float) (fl+i);
}
\end{lstlisting}
\item \texttt{void passLong(long l)} --- Takes a long number as argument and prints information about size of types in C++, Python and Java
\begin{lstlisting}[language=java, frame=none, numbers=none]
public void passLong(long l)
{
    System.out.println("Maximal value of Java long is:     " + Long.MAX_VALUE);
    System.out.println("Maximal value of C++ long long is: 9223372036854775807");
    System.out.println("Value passed from Python as long:  " + l);
}
\end{lstlisting}
\end{enumerate}

Assume that you have saved your class into the directory named \texttt{example}. Go there and compile a class:
\begin{verbatim}
$ cd example
$ javac HelloUniverce.java
\end{verbatim}

When compilation finished you'll see a \texttt{HelloUniverce.class} file. That's what we need. The next step is more difficult than previous: we will compile library \texttt{AmiCoPyJava} to get a loadable file of the dynamic library. We have already described this step in ~\autoref{subs:compile}.

After you have compiled a library and got a \texttt{libAmiCoPyJava.so} file for \texttt{Linux} or \texttt{libAmiCoPyJava.dylib} file for \texttt{Mac OS X} write a \texttt{Python} script that will use this library to call methods from our fresh \texttt{Java} class. First of all import some general and problem specific modules (listing~\ref{listing:neededModules}):

\begin{lstlisting}[caption=Needed modules, label=listing:neededModules]
import sys
import ctypes
from ctypes import *
from ctypes.util import find_library
\end{lstlisting}

To make passing of the arrays between \texttt{Python} and \texttt{Java} possible, copy the source of this class in your script:

\begin{lstlisting}[caption=ListPOINTER]
class ListPOINTER(object):
    def __init__(self, etype):
        self.etype = etype

    def from_param(self, param):
        if isinstance(param, (list, tuple)):
            return (self.etype * len(param))(*param)
        else:
            return param
\end{lstlisting}

Now load the library. If you are a Linux user and have not exported the '.so' file to your \texttt{LD\_LIBRARY\_PATH} use this code (listing~\ref{listing:loadingAmiCoFile1}):

\begin{lstlisting}[caption=Loading AmiCo library, label=listing:loadingAmiCoFile1]
loadName = './libAmiCoPyJava.so'
libamico = ctypes.CDLL(loadName)
\end{lstlisting}

If you are a Mac user or exported the path with the library to \texttt{LD\_LIBRARY\_PATH} \texttt{Linux} you can use this code (listing~\ref{listing:loadingAmiCoFile2}):

\begin{lstlisting}[caption=Loading AmiCo library, label=listing:loadingAmiCoFile2]
name =  'AmiCoPyJava' # name of the library
loadName = find_library(name)
libamico = ctypes.CDLL(loadName)
\end{lstlisting}

Please, note, that \texttt{libamico} should be a \textbf{global} variable to be accessed from any function. So, we have loaded a library and now we ready to create a \texttt{JVM} and load a class (listing~\ref{listing:initializingLibraryAndLoadingClass}):

\begin{lstlisting}[caption=Initializing library and loading class, label=listing:initializingLibraryAndLoadingClass]
#create JVM without any additional startup options
libamico.amicoInitialize()
#set internal amico types (local function)
initAmiCo()
#load a class in to the JVM
className = "HelloUniverce"    
libamico.createGeneralEnvironment(className)
\end{lstlisting}

Now we are ready to call any method from the class using AmiCo functions. Let's write a separate function for each method (listing~\ref{listing:callingMethodsFromTheClass}):

\begin{lstlisting}[caption=Initializing library and loading class, label=listing:callingMethodsFromTheClass]
def FuncPrintHelloUniverce():
    """Calls method that prints a simple string 'Hello Univerce!'"""
    #use global variable
    global libamico
    #take a method ID
    helloUniverce = libamico.getMethod("printHelloUniverce", "()V")
    #method doesn't return any value so we use a 'callVoidMethod' function
    libamico.callVoidMethod(helloUniverce)
    
def FuncPrintCustomString(str):
    """Passes a string in to the Java method"""
    global libamico
    #take a method ID
    printCustomString = libamico.getMethod("printCustomString", "(Ljava/lang/String;)V")
    #function callVoidMethod takes a C pointer and a string as parameters
    libamico.callVoidMethod.argtypes = [ctypes.c_void_p,  c_char_p]
    #method doesn't return any value so we use a 'callVoidMethod' function
    libamico.callVoidMethod(printCustomString, str)
    
def FuncPassArrayOfIntegers():
    """Calls the method that takes an array of integers as parameter and 
    prints this array to the screen"""
    array = [1, 2, 3]
    #take a method ID
    passArrayOfIntegers = libamico.getMethod("passArrayOfIntegers", "([I)V")
    #function callVoidMethod takes a C pointer and a Python tuple
    libamico.callVoidMethod.argtypes = [c_void_p,  ListPOINTER(c_int)]
    #cause there is an array in parameters we need to set it's size
    #we pass 1 array with length 3
    libamico.setSizeOfArrays(1, (3,))
    #method doesn't return any value so we use a 'callVoidMethod' function
    libamico.callVoidMethod(passArrayOfIntegers, tuple(array))
    
def FuncGetArrayOfFloats():
    """Calls a method that will return an array of floats"""
    #take a method ID
    getArrayOfFloats = libamico.getMethod("getArrayOfFloats", "()[F")
    #function callFloatArrayMethod takes only one
    #required argument -- ID of the method to be called
    libamico.callFloatArrayMethod.argtypes = [c_void_p]
    #function 'callFloatArrayMethod' will return result of
    #caling 'getArrayOfFloats' method,
    #i.e. an array of floats
    res = libamico.callFloatArrayMethod(getArrayOfFloats)
    print "result of 'getArrayOfFloats' method: ", res
    
def FuncGetIntAsString():
    """Calls method with parameter -- integer and takes a result of calling
    this method -- a string representation of the passed integer"""
    #take a method ID
    getIntAsString = libamico.getMethod("getIntAsString", "(I)Ljava/lang/String;")
    #takes a method ID and an integer number.
    #Type of returning value was changed in 'initAmiCo' function
    libamico.callStringMethod.argtypes = [c_void_p, c_int]
    #method returns a Sting value so we use 'callStringMethod' function
    res = libamico.callStringMethod(getIntAsString, 5)
    print "result of 'getIntAsString' method: ", res

def FuncSumOfFloatAndInt_AsFloat():
     """Calls a method that takes two parameters -- float pointing number and an
    integer number and returns a float pointing number -- sum of this two numbers"""
    sumOfFloatAndInt_AsFloat = libamico.getMethod("sumOfFloatAndInt_AsFloat", "(FI)F")
    #takes C pointer, double and int.
    #Yes, exactly double. When do you pass a float pointing number in to a method it
    #should have a type double casue of some C++ restrictions, but in Java method
    #should take a float
    libamico.callFloatMethod.argtypes = [c_void_p, c_double, c_int]
    #returns a float
    res = libamico.callFloatMethod(sumOfFloatAndInt_AsFloat, c_double(2.2), c_int(5))
    print "result of 'sumOfFloatAndInt_AsFloat' method: ", res
    
def passLong():
    """Passes in to a Java method maximal value of type long in Java and Python"""
    passLong = libamico.getMethod("passLong", "(J)V")
    #Java's and Python's long type is equivalent to long long or __int64 in C++
    libamico.callVoidMethod.argtypes = [c_void_p, c_longlong]
    libamico.callVoidMethod(passLong, 9223372036854775807)
\end{lstlisting}

In the end we should close \texttt{AmiCo} and destroy JVM environment with \texttt{closeAmiCo} function from \texttt{libamico}. Note, that file of the dynamic library, compiled \texttt{Java} class and a \texttt{Python} script should be located in the same directory.

\subsubsection{Error messages and handling} % (fold)
\label{ssub:error_messages_and_handling}

% subsubsection error_messages_and_handling (end)
If you got an error message while running a python script of this kind:
\begin{lstlisting}[language=bash, frame=none, numbers=none, keywordstyle=\color{black}]
OSError: libjvm.so: cannot open shared object file: No such file or directory
\end{lstlisting}

that means that you don't have correct path to your \texttt{Java} dynamic libraries. In that case try to run your program using an \texttt{AmiCoRunner.sh} script located in the root directory of the \texttt{AmiCoPyJava} project. If you still have any error messages you are welcome to our Google Group \footnote{libamico@googlegroups.com} or to a web site ~\href{http://amico.karakovskiy.com}{http://amico.karakovskiy.com} to solve your problem.

% \chapter{Setup for MDRNNs}
% Exhaustive description of the setup goes here with all parameters. 